<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
/**
 * 订单模型
 */
class Out_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	
	/**
	 * 
	 */
	public function out_list_all($page,$perpage,$user_id) {
		$sql = "SELECT ";
		$sql .= "ao.`create_time` AS sq_time,";
		$sql .= "ol.id,";
		$sql .= "ol.money,";
		$sql .= "ol.day_num,";
		$sql .= "ol.bianhao,";
		$sql .= "ol.out_day_num,";
		$sql .= "ol.`create_time` AS hz_time ,";
		$sql .= "ao.`user_id`,";
		$sql .= "ao.old_money,";
		$sql .= "ao.pipei_rate, ";
		$sql .= "ao.out_rate, ";
		$sql .= "ao.level_rate, ";
		$sql .= "ao.daynum, ";
		$sql .= "ao.new_money ";
		$sql .= "FROM `pc_ddth_out_log` AS ao,`pc_ddth_order_log` AS ol";
		$sql .= " WHERE ol.`id` = ao.`ol_id` ";
		$sql .= " AND ao.user_id =".$user_id;
		$sql .= " AND ol.dakuan = '1'";
		$sql .= " AND ol.shoukuan = '1'";
		$sql .= " ORDER BY ao.create_time desc";
		$sql .= " limit ".$perpage*($page-1).','.$perpage;
		// echo $sql;
		$query = $this->db->query ( $sql );
	
		return $query->result_array ();
	}
	
	/**
	 * 
	 */
	public function out_list_all_count($user_id) {
		$sql = "SELECT ";
		$sql .= " COUNT(ao.id) AS num ";
		$sql .= " FROM `pc_ddth_out_log` AS ao,`pc_ddth_order_log` AS ol";
		$sql .= " WHERE ol.`id` = ao.`ol_id`";
		$sql .= " AND ao.user_id =".$user_id;
		$sql .= " AND ol.dakuan = '1'";
		$sql .= " AND ol.shoukuan = '1'";
		
		//echo $sql;
		$query = $this->db->query ( $sql );	
		return $query->row_array()['num'];
	
		//return $this->db->count_all_results('pc_ddth_out_log');
	}
	
}
